
using System;
using System.Data;
using System.Data.SqlClient;
using ERP_RORZE_ORDER.Common;
using ERP_RORZE_ORDER.Common.ValueObject;
using ERP_RORZE_TOOL.DBAccess;

namespace ERP_RORZE_ORDER.DBAccess
{

	public class MakerDAO : BaseDAO
	{
        #region Basic Method

        public static DataTable GetAll()
        {
            return ExcuteProcedure(OrderConstants.StoreProcedure.Maker.GetAll);
        }

        public static DataTable GetAll(string storedProc)
        {
            return ExcuteProcedure(storedProc);
        }

        public static DataTable GetOne(string makerId)
        {
            try
            {
                var parameters = new SqlParameter[]
                    {
						CreateParameter("@MakerID", SqlDbType.NVarChar, makerId)
                    };
                return ExcuteProcedure(OrderConstants.StoreProcedure.Maker.GetOne, parameters);

            }
            catch (Exception e)
            {
                throw new BaseDAO.MyException(e);
            }

        }

        public static Maker LoadOne(string makerId)
        {
            Maker o = new Maker();
            DataTable dt = GetOne(makerId);
            if (dt.Rows.Count > 0)
            {
                //o.ID = int.Parse(dt.Rows[0][OrderConstants.Entities.Maker.FieldName.ID].ToString());
                o.MakerID = dt.Rows[0][OrderConstants.Entities.Maker.FieldName.MakerID].ToString();
                o.EnglishName = dt.Rows[0][OrderConstants.Entities.Maker.FieldName.EnglishName].ToString();
                o.JapanName = dt.Rows[0][OrderConstants.Entities.Maker.FieldName.JapanName].ToString();

            }

            return o;
        }

        public static int Insert(Maker o)
        {
            try
            {
                var parameters = new SqlParameter[]
                    {
                        CreateParameter("@MakerID", SqlDbType.NVarChar, o.MakerID),
                        CreateParameter("@EnglishName", SqlDbType.NVarChar, o.EnglishName),
                        CreateParameter("@JapanName", SqlDbType.NVarChar, o.JapanName),
                    };

                return ExecuteNonQueryProcedure(OrderConstants.StoreProcedure.Maker.Insert, parameters);

            }
            catch (Exception e)
            {
                throw new BaseDAO.MyException(e);
            }

        }

        public static int Update(Maker o)
        {
            try
            {
                var parameters = new SqlParameter[]
                    {
                        CreateParameter("@TempID", SqlDbType.NVarChar, o.TempId),
                        CreateParameter("@MakerID", SqlDbType.NVarChar, o.MakerID),
                        CreateParameter("@EnglishName", SqlDbType.NVarChar, o.EnglishName),
                        CreateParameter("@JapanName", SqlDbType.NVarChar, o.JapanName),
                    };

                return ExecuteNonQueryProcedure(OrderConstants.StoreProcedure.Maker.Update, parameters);
            }
            catch (Exception e)
            {
                throw new BaseDAO.MyException(e);
            }
        }

        public static int Delete(Maker o)
        {
            try
            {
                var parameters = new SqlParameter[]
                    {
                        CreateParameter("@MakerID", SqlDbType.NVarChar, o.MakerID)
                    };

                return ExecuteNonQueryProcedure(OrderConstants.StoreProcedure.Maker.Delete, parameters);
            }
            catch (Exception e)
            {
                throw new BaseDAO.MyException(e);
            }
        }

        public static DataTable GetTemplateTable()
        {
            DataTable table = new DataTable("243_Maker");

            return table;
        }


        #endregion

	}
	
}
